package com.yuneec.fly.dialogs;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.yuneec.fly.GlobalParams;
import com.yuneec.fly.R;

/**
 * Created by peng.gao on 2016/7/27.
 */
@SuppressLint("ValidFragment")
public class ConfirmWayPointDialog extends ConfirmDialog {
    public ConfirmWayPointDialog(String message, OnConfirmListener onConfirmListener, OnCancelListener onCancelListener) {
        super(message, onConfirmListener, onCancelListener);
    }

    private RadioGroup mRadioGroup;
    private RadioButton mRadioButton0;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        mRadioGroup = (RadioGroup) view.findViewById(R.id.confirm_dialog_radioGroup);
        mRadioButton0 = (RadioButton) view.findViewById(R.id.radioButton0);
        if (GlobalParams.sCurrentWayPointUserIndex == 1) {
            mRadioGroup.setVisibility(View.GONE);
        } else {
            mRadioGroup.setVisibility(View.VISIBLE);
            setSelectedIndex(GlobalParams.sCurrentWayPointUserIndex);
            GlobalParams.sIsStartWayPointFromSelectedIndex = true;
        }

        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.radioButton0:
                        GlobalParams.sIsStartWayPointFromSelectedIndex = true;
                        break;
                    case R.id.radioButton1:
                        GlobalParams.sIsStartWayPointFromSelectedIndex = false;
                        break;
                }
            }
        });
        return view;
    }

    public void setSelectedIndex(int index) {
        String text = String.format(getResources().getString(R.string.from_index_waypoint), index);
        mRadioButton0.setText(text);
    }
}
